package com.app.service.Impl;

import com.app.mapper.RecruitMapper;
import com.app.model.RecruitModel;
import com.app.service.RecruitService;
import com.app.vo.RecruitModelVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RecruitServiceImpl implements RecruitService {
    @Autowired
    RecruitMapper recruitMapper;

    //查询所有招工用工
    @Override
    public RecruitModelVo getRecruitList(Integer page, Integer limit) {
        Page<RecruitModel> page1 = new Page<>(page, limit);
        Page<RecruitModel> recruitPage = recruitMapper.selectPage(page1, null);
        List<RecruitModel> recruitList = recruitPage.getRecords();
        int count = (int) recruitPage.getTotal();
        RecruitModelVo modelVo=new RecruitModelVo();
        modelVo.setList(recruitList);
        modelVo.setCount(count);
        return modelVo;
    }

    @Override
    public void insert(RecruitModel recruitModel) {
        this.recruitMapper.insert(recruitModel);
    }

    @Override
    public void update(RecruitModel recruitModel) {
        RecruitModel model=this.recruitMapper.selectById(recruitModel.getId());
        if(model!=null)
        {
            this.recruitMapper.updateById(recruitModel);
        }
    }

    @Override
    public Map<String,Object> listByPage(Integer page, Integer limit, QueryWrapper<RecruitModel> queryWrapper) {
        Page<RecruitModel> recruitModelIPage=new Page<>();
        recruitModelIPage.setPages(page);
        recruitModelIPage.setSize(limit);
        Page<RecruitModel> articleModelPage = this.recruitMapper.selectPage(recruitModelIPage,queryWrapper);
        Map<String, Object> response = new HashMap<>();
        response.put("list", articleModelPage.getRecords());
        response.put("count", articleModelPage.getTotal());
        return response;
    }

    @Override
    public void del(Integer id) {
        this.recruitMapper.deleteById(id);
    }

    @Override
    public RecruitModel getRecruitById(Integer id) {
        RecruitModel recruitModel = recruitMapper.selectById(id);
        return recruitModel;
    }
}
